package com.smh.a03DateDemo3;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;

public class InstantDemo1 {
    public static void main(String[] args) {

        //获取标准时间,不带时区
        Instant instant = Instant.now();
        System.out.println(instant);
        //获取指定时间
        Instant instant1 = Instant.ofEpochMilli(0L);
        System.out.println(instant1);
        Instant instant2 = Instant.ofEpochSecond(1L);
        System.out.println(instant2);
        //后面是纳秒
        Instant instant3 = Instant.ofEpochSecond(1L,1000000000L);
        System.out.println(instant3);

        //指定时区
        ZonedDateTime time = Instant.now().atZone(ZoneId.of("Asia/Shanghai"));
        System.out.println(time);

        //判断
        Instant instant4 = Instant.ofEpochMilli(0L);
        Instant instant5 = Instant.ofEpochMilli(1000L);

        System.out.println(instant4.isBefore(instant5));
        System.out.println(instant4.isAfter(instant5));

        //减一秒
        Instant instant6 = Instant.ofEpochMilli(21413421224L);
        System.out.println(instant6);
        Instant instant7 = instant6.minusSeconds(1);
        System.out.println(instant7);
        //加一秒
        Instant instant8 = instant6.plusSeconds(1);
        System.out.println(instant8);


    }
}
